import { Message } from 'element-ui';
import validate from '@/utils/validate';

const { isEmpty } = validate;

export default function check (checkObj, modifyPass) {
  let checkRes = true;
  const validKeys = [
    { key: 'name', name: '姓名' },
    { key: 'employeeId', name: '工号' },
    { key: 'sex', name: '性别' },
    { key: 'birthday', name: '生日' },
    { key: 'mobile', name: '手机' },
    { key: 'age', name: '年龄' },
    { key: 'oneLevelDept', name: '一级部门' },
    // { key: 'twoLevelDept', name: '二级部门' },
    { key: 'workingStatus', name: '在职状态' },
    { key: 'position', name: '职位' },
    { key: 'username', name: '登录账号' },
    { key: 'accountStatus', name: '账号状态' },
    { key: 'roles', name: '角色' }
  ];

  for (const valid of validKeys) {
    const checkMid = isEmpty(checkObj[valid.key]);
    if (checkMid) {
      Message.error(`${valid.name}不能为空`);
      checkRes = false;
      break;
    }
  }

  if (modifyPass && (checkObj.password !== checkObj.passwordAgain)) {
    Message.error('两次密码不一样，请重新输入');
    checkRes = false;
  }

  return checkRes;
}
